package com.nulldev.util.networking.npacket4.extensions.protocol.mux;

public enum MuxedStreamType {
	/* single channel */

	WRITE_ONLY(1, ChannelType.WRITE_ONLY),
	READ_ONLY(2, ChannelType.READ_ONLY),
	READ_AND_WRITE(3, ChannelType.READ_AND_WRITE),

	/* double channel */

	WRITE_ONLY_L(4, ChannelType.WRITE_ONLY),
	WRITE_ONLY_R(5, ChannelType.WRITE_ONLY),

	READ_ONLY_L(6, ChannelType.READ_ONLY),
	READ_ONLY_R(7, ChannelType.READ_ONLY),

	READ_AND_WRITE_L(8, ChannelType.READ_AND_WRITE),
	READ_AND_WRITE_R(9, ChannelType.READ_AND_WRITE),

	/* triple channel */

	WRITE_ONLY_T_LEFT(10, ChannelType.WRITE_ONLY),
	WRITE_ONLY_T_CENTER(11, ChannelType.WRITE_ONLY),
	WRITE_ONLY_T_RIGHT(12, ChannelType.WRITE_ONLY),

	READ_ONLY_T_LEFT(13, ChannelType.READ_ONLY),
	READ_ONLY_T_CENTER(14, ChannelType.READ_ONLY),
	READ_ONLY_T_RIGHT(15, ChannelType.READ_ONLY),

	READ_AND_WRITE_T_LEFT(16, ChannelType.READ_AND_WRITE),
	READ_AND_WRITE_T_CENTER(17, ChannelType.READ_AND_WRITE),
	READ_AND_WRITE_T_RIGHT(18, ChannelType.READ_AND_WRITE),

	;

	public static final int MAXIMUM_CHANNEL_COUNT = 8;
	private final short id;
	private final ChannelType type;

	private MuxedStreamType(final int id, final ChannelType type) {
		this.id = (short) id;
		this.type = type;
	}

	public short id() {
		return this.id;
	}

	public ChannelType type() {
		return this.type;
	}

	public static enum ChannelType {
		READ_ONLY,
		WRITE_ONLY,
		READ_AND_WRITE
	}

	public static MuxedStreamType get(final int id) {
		for (final MuxedStreamType mx : values())
			if (mx.id == id)
				return mx;
		return null;
	}
}
